package com.ccc.boot.system.controller;

import com.ccc.boot.base.BaseController;
import com.ccc.boot.constant.CommonConstant;
import com.ccc.boot.exception.BusinessException;
import com.ccc.boot.response.ResponseCode;
import com.ccc.boot.response.ResponseResult;
import com.ccc.boot.system.entity.SysApi;
import com.ccc.boot.system.pojo.AuthApiVO;
import com.ccc.boot.system.pojo.AuthMenuTree;
import com.ccc.boot.system.service.SysApiService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 按钮接口资源 REST接口
 *
 * @author superC
 * @version 0.1.0
 * @date 2022/4/1
 */

@RestController
@RequestMapping(CommonConstant.SYS_URI_PREFIX + "/resourceApi")
public class SysApiController extends BaseController<SysApi, SysApiService> {

    /**
     * 根据菜单id，获取所选角色已授权的按钮资源集
     *
     * @date 2022/4/8 13:23
     * @param roleId
     * @return {@link ResponseResult}
     * @author superC
     */
    @GetMapping("/getAuthApiList/{roleId}/{menuId}")
    public ResponseResult getAuthApiList(@PathVariable Long roleId, @PathVariable Long menuId) {
        try {
            List<AuthApiVO> tree = service.getAuthApiList(roleId, menuId);
            return ResponseResult.success("获取按钮资源数据成功", tree);
        } catch (Exception e) {
            logger.error("【捕获异常-获取按钮资源操作】\r\n异常记录：", e);
            throw new BusinessException(ResponseCode.DATA_GET_ERROR);
        }
    }



}